//
//  EGShoppingCartView.m
//  Orchard
//
//  Created by ios001 on 16/8/20.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "EGShoppingCartView.h"

@interface EGShoppingCartView()

@property (nonatomic,strong) UIView      *tempView;
@property (nonatomic,strong) UIImageView *img;
@property (nonatomic,strong) UILabel     *promptLabel;
@property (nonatomic,strong) UIButton    *shopButton;

@end

@implementation EGShoppingCartView

IMPLEMENTATION_SINGLETON(EGShoppingCartView)

#pragma mark - 1.重写 init 方法,设置界面
- (instancetype)init
{
    self = [super init];
    if (self) {
        // 添加子控件
        [self setupUI];
    }
    return self;
}

- (void)layoutSubviews{
    [self setupLayout];
}

#pragma mark - 添加子控件
- (void)setupUI{
    [self addSubview:self.tempView];
    [self.tempView addSubview:self.img];
    [self.tempView addSubview:self.promptLabel];
    [self.tempView addSubview:self.shopButton];
    
    [self.shopButton addTarget:self action:@selector(shopButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (IBAction)shopButtonClick:(id)sender{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dismiss" object:self];
}

- (void)setupLayout{
    [self.tempView makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.leading.trailing.equalTo(self);
        make.top.equalTo(self).offset(64);
    }];
    
    [self.img makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tempView).offset(150);
        make.centerX.equalTo(self);
    }];
    
    [self.promptLabel makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    
    [self.shopButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.promptLabel.bottom).offset(25);
        make.centerX.equalTo(self);
        make.width.offset(150);
        make.height.offset(30);
    }];
}

#pragma mark - 懒加载控件
- (UIView *)tempView{
    if (_tempView == nil) {
        _tempView = [UIView new];
        _tempView.backgroundColor = [UIColor whiteColor];
    }
    return _tempView;
}

- (UIImageView *)img{
    if (_img == nil) {
        _img = [UIImageView new];
        _img.image = [UIImage imageNamed:@"v2_shop_empty"];
        [_img sizeToFit];
    }
    return _img;
}

- (UILabel *)promptLabel{
    if (_promptLabel == nil) {
        _promptLabel = [UILabel new];
        _promptLabel.textColor = [UIColor grayColor];
        _promptLabel.text = @"亲,购物车空空的耶~赶紧挑好吃的吧";
    }
    return _promptLabel;
}

- (UIButton *)shopButton{
    if (_shopButton == nil) {
        _shopButton = [UIButton new];
        [_shopButton setTitle:@"去逛逛" forState:UIControlStateNormal];
        [_shopButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [_shopButton setBackgroundImage:[UIImage imageNamed:@"btn.png"] forState:UIControlStateNormal];
    }
    return _shopButton;
}


@end
